#include<stdio.h>
int main()
{
	char huowu[7];
	int danjia[6];
	int jige[6];
	int a=1;
	int tongdao[6];
	int b=1;
	for(;b<6;b++){
		tongdao[b]=b;
	}
	chehui1:
	for(;a<6;a++)
	{
		printf("请输入通道%d的货物种类、数量、单价：",a);
		scanf(" %c %d %d",&huowu[a],&jige[a],&danjia[a]);
	}
	int shifou1;
	printf("是否要回到上一步操作，若是，请输入1，若不是，请输入0：");
	scanf("%d",&shifou1);
	if(shifou1==1){
		goto chehui1;
	}
	int i=1;
	for(;i<6;i++){
		printf(" %d:",tongdao[i]);
		int c=1;
		for(;c<=jige[i];c++){
			printf("%c",huowu[i]);
		}
		printf(" %d\n",danjia[i]);
	}
	chehui2:
	int zongjia;
	int shuliang[6];
	int d=1;
	for(;d<6;d++){
		printf("请输入您要在%d通道购买货物的数量，若不购买，请输入0：",d);
		scanf("%d",&shuliang[d]);
	}
	int f=1;
	for(;f<6;f++){
		while(shuliang[f]>jige[f]){
			printf("通道%d的货物只有%d个，请重新输入购买数量：",f,jige[f]);
			scanf("%d",&shuliang[f]);
		}}
	int shifou2;
	printf("是否要回到上一步操作，若是，请输入1，若不是，请输入0：");
	scanf("%d",&shifou2);
	if(shifou2==1){
		goto chehui2;
	}
	int e=1;
	for(;e<6;e++){
		zongjia+=danjia[e]*shuliang[e];
	}
	int qian;
	int zongtouru=0;
	printf("请投入1元或2元或5元：");
	scanf("%d",&qian);
	while(qian!=1&&qian!=2&&qian!=5){
		printf("只能投入1元或2元或5元，请重新投币：");
		scanf("%d",&qian);
	}
	zongtouru=zongtouru+qian;
	while(zongtouru<zongjia){
		printf("请继续投入1元或2元或5元:");
		scanf("%d",&qian);
		while(qian!=1&&qian!=2&&qian!=5){
			printf("只能投入1元或2元或5元，请重新投币：");
			scanf("%d",&qian);
		}
		zongtouru=zongtouru+qian;
	}
	if(zongtouru>zongjia){
		printf("购买完毕，找您%d元\n",zongtouru-zongjia);
	}
	else{
		printf("购买完毕");
	}
	
	return 0;
}
